<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
<script>
  $(function () {
    /** Tabs: */
    $('.primary .switch .switch--item').on('click', function () {
      const option = $(this)[0].className.match(/option-\d+/)[0].split('option-')[1];
      $('.primary .switch .switch--item').removeClass('selected');
      $(`.primary .content`).addClass('hidden');

      $(`.primary .switch .switch--item.option-${option}`).addClass('selected');
      $(`.primary .content.option-${option}`).removeClass('hidden');
    });
  });
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/3.0.2/tocbot.min.js"></script>
<script>
  $(function() {
    var oldtoc = document.getElementById('toctitle').nextElementSibling;
    var newtoc = document.createElement('div');
    newtoc.setAttribute('id', 'tocbot');
    newtoc.setAttribute('class', 'js-toc');
    oldtoc.parentNode.replaceChild(newtoc, oldtoc);
    tocbot.init({
      contentSelector: '#content',
      headingSelector: 'h1, h2, h3, h4, h5',
      ignoreSelector: '.discrete',
      smoothScroll: false
    });
    var handleTocOnResize = function () {
      var width = window.innerWidth
          || document.documentElement.clientWidth
          || document.body.clientWidth;
      if (width < 768) {
        tocbot.refresh({
          contentSelector: '#content',
          headingSelector: 'h1, h2, h3, h4, h5',
          collapseDepth: 6,
          ignoreSelector: '.discrete',
          throttleTimeout: 1000,
          smoothScroll: false
        });
      } else {
        tocbot.refresh();
      }
    };
    window.addEventListener('resize', handleTocOnResize);
    handleTocOnResize();
  });
</script>

<script src="/js/clipboard.min.js"></script>
<script>
  $(function() {
    new ClipboardJS('.clipboard')
    .on('success', function(e) {
      e.clearSelection();
    });
  });
</script>
